package tetrinet.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.event.dom.client.KeyCodes;
import com.google.gwt.event.dom.client.KeyUpEvent;
import com.google.gwt.event.dom.client.KeyUpHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.DialogBox;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.Panel;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.user.client.ui.SimplePanel;
import com.google.gwt.user.client.ui.TextBox;
import com.google.gwt.user.client.ui.VerticalPanel;

/**
 * Entry point classes define <code>onModuleLoad()</code>.
 */
public class TetrinetGAE implements EntryPoint {
	
	public static final native String[] split(String string, String separator) /*-{
    return string.split(separator);
}-*/;
	/**
	 * This is the entry point method.
	 */
	public void onModuleLoad() {
		
		String channel = RootPanel.get("game_token").getElement().getAttribute("value");
		int player_id = Integer.parseInt(RootPanel.get("player").getElement().getAttribute("value"));
		String player_name = RootPanel.get("player_name").getElement().getAttribute("value");
		String[] known_players = split(RootPanel.get("known_players").getElement().getAttribute("value"),",");
		String room = RootPanel.get("room").getElement().getAttribute("value");
		TetrinetGame g = new TetrinetGame(channel,player_id,player_name,known_players,room);
		RootPanel.get("game_area").add(g.getSurface());
		g.initialize();
		g.start();
	}
}
